package com.ch.android.baselib

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding

/**
 * Author: conghao
 * Date: 2023/12/26 14:12
 * Description: BaseBindingActivity
 */
abstract class BaseBindingActivity<VDB : ViewDataBinding> : AppCompatActivity() {

    protected val mBinding: VDB by lazy {
        DataBindingUtil.setContentView(this, getLayout())
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (getLayout() == 0) {
            throw NotImplementedError("错误：未实现 getLayout() 方法！")
        }
        mBinding.lifecycleOwner = this
    }

    abstract fun getLayout(): Int

    override fun onDestroy() {
        super.onDestroy()
        mBinding.unbind()
    }
}